<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec"    uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>

</head>

<body class="ms-theme-blue">

  <%@ include file="/WEB-INF/include/header.jsp"%>
    
  <%@ include file="/WEB-INF/include/submenu.jsp"%>
  
  <div class="container-fluid ms-container has-ms-sidemenu">
    
    <ol class="ms-breadcrumb breadcrumb">
      <li class="active">行驶公里数&nbsp;-&nbsp;设置</li>
    </ol>
    
    <div class="ms-content-layout">
    
      <form class="form-horizontal ms-form form-personal-info" method="GET" action="${ctx.host}/facility-distances" >
        
        <input type="hidden" name="prepare" value="true"/>
        
        <div class="form-group ms-form-group">
          <label class="col-xs-2 control-label"><span class="text-red">*</span>公司</label>
          <div class="col-xs-3">
             <c:choose>
             
                <c:when test="${not empty currentPrincipal.transOrgId}">
                    <p class="form-control-static">${persist.organization(currentPrincipal.transOrgId).name}</p>
                    <input type="hidden" name="orgId" value="${currentPrincipal.transOrgId}"/>
                </c:when>
                
                <c:otherwise>
                    <select class="select2 form-control" name="orgId" tabindex="1" data-validate="required" > 
                      <option></option>
                      <c:forEach items="${orgIds}" var="organizationId">
                        <option value="${organizationId}">${persist.organization(organizationId).name}</option>
                      </c:forEach>
                    </select>
                </c:otherwise>
             
             </c:choose>
             
          </div>
        </div>
        
        <div class="form-group ms-form-group">
          <label class="col-xs-2 control-label"><span class="text-red">*</span>起始地（装卸地）</label>
          <div class="col-xs-3 modal-search-warp">
            <input autocomplete="off" tabindex="2" type="text" name="fromLoadPlace" data-validate="required" 
                   class="form-control fromloadplace-search modal-search" data-value-name="fromLoadPlaceId" 
                    placeholder="请填写起始地"  data-modal-search="#modal-search-fromloadplace">
            <a href="javascript:void(0);" class="btn" data-target="#modal-search-fromloadplace" data-toggle="modal">
              <span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span>
            </a>
          </div>
          <label class="col-xs-2 control-label"><span class="text-red">*</span>目的地（装卸地）</label>
           <div class="col-xs-3 modal-search-warp">
            <input autocomplete="off" tabindex="3" type="text" name="toLoadPlace" data-validate="required"
                   class="form-control toloadplace-search modal-search" data-value-name="toLoadPlaceId" 
                   placeholder="请填写目的地"  data-modal-search="#modal-search-toloadplace">
            <a href="javascript:void(0);" class="btn" data-target="#modal-search-toloadplace" data-toggle="modal">
              <span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span>
            </a>
          </div>
        </div>
        
        <div class="form-group ms-form-group">
            <div class="col-xs-6 col-xs-offset-3 ms-operation-group top-margin-20 text-center">
            <div class="col-xs-5">
              <button type="reset" class="btn btn-block btn-default btn-remove">重置</button>
            </div>
            <div class="col-xs-5">
              <button type="submit" class="btn btn-block btn-primary" tabindex="4">确定</button>
            </div>
            </div>
        </div>

      </form>
      <hr style="margin-top: 30px;">
      
      <table class="table table-hover ms-table" style="margin-top: 30px;">
        <thead>
            <tr>
              <th>运输公司</th>
              <th>起始地</th>
              <th>目的地</th>
              <th>行驶公里数</th>
              <th>行驶周期</th>
              <th>操作</th>
            </tr>
        </thead>
        <tbody>
             <c:if test="${empty facilityDistances and not empty organization}">
               <tr>
                   <td>${organization.name}</td>
                   <td>${fromLoadPlace.name}</td>
                   <td>${toLoadPlace.name}</td>
                   <td>未设置</td>
                   <td>未设置</td>
                   <td>
                     <a href="${ctx.host}/facility-distances/create?organization=${organization.id}&fromLoadPlace=${fromLoadPlace.id}&toLoadPlace=${toLoadPlace.id}"  data-target="#create" data-toggle="modal" title="CREATE">设置行驶公里数</a>
                   </td>
               </tr>
             </c:if>
             <c:if test="${not empty facilityDistances}">
                 <c:forEach var="facilityDistance" items="${facilityDistances}">
                     <tr>
                       <td>${facilityDistance.organization.name}</td>
                       <td>${facilityDistance.fromLoadPlace.name}</td>
                       <td>${facilityDistance.toLoadPlace.name}</td>
                       <td><fmt:formatNumber value="${facilityDistance.facilityDistance}" maxFractionDigits="2" pattern="0.00"/> </td>
                       <td>${facilityDistance.shipmentCycle}</td>
                       <td>
                         <a href="${ctx.host}/facility-distances/${facilityDistance.id}/edit"  data-target="#edit" data-toggle="modal" title="Edit">修改驶公里数</a>
                       </td>
                   </tr>
                 </c:forEach>
             </c:if>
        </tbody>
      </table>
      
    </div> 
  </div>       
  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource type="script" root="${ctx.resource}/build" src="js/page/data/business/facility-distance-prepare.js" />
  <script type="text/javascript">
      require(['page/data/business/facility-distance-prepare'], function(page) {
        page.init()
      })
  </script>

</body>
</html>